package cn.edu.gench.learn.day2;

/**
 * @auther zhuzhongbiao
 * @date 2017/3/22 0022
 *
 * 作业2
 *
 * http://www.baidu.com?name=123&gender=1
 * name is 1234
 * gender is 男
 */
public class StringTest {

    public void findStr2(String original,String flag) {
        System.out.println(original.indexOf(flag));
        if (original.indexOf(flag) != -1) {
            System.out.println("包含");
        } else {
            System.out.println("不包含");
        }
    }
    public static void main(String[] args) {
        StringTest stringTest = new StringTest();
//        stringTest.findStr("abc123","p");
        //stringTest.findStr2("abc1231","1");
        //stringTest.replaceStr("abc123","p","a");

        stringTest.subString("http://www.baidu.com?name=123&gender=1","name","&");
    }

    private void subString(String str, String first, String second) {
        int firstIndex = str.indexOf(first);
        int secondIndex = str.indexOf(second);
        if(firstIndex == -1 || secondIndex == -1 ){
            System.out.println("未找到");
            return;
        }
        //[1,2)
        String result = str.substring(firstIndex+5,secondIndex);
        System.out.println(result);
    }


    public void replaceStr(String original,String newStr,String oldStr){
        original =  original.replace(oldStr,newStr);
        System.out.println(original);
    }


    public void findStr(String original,String flag){
        if(original.contains(flag)){
            System.out.println("包含");
        }else {
            System.out.println("不包含");
        }
    }

}
